<template>
  <div id="main">
    <el-row class="space">
      <el-col :span="24">
        <ul class="list">
          <li @click="index()"><h1 class="logo"><el-icon class="icon-kaoshi"><Reading/></el-icon>&nbsp;<small>Exam-Online</small></h1></li>
          <li>
            <el-dropdown>
              <el-button class="el-dropdown-link" round>
                {{mode}}<el-icon class="el-icon--right"><arrow-down /></el-icon>
              </el-button>
              <template #dropdown>
                <el-dropdown-menu>
                  <el-dropdown-item @click="practice">练习模式</el-dropdown-item>
                  <el-dropdown-item class="exit" @click="exam">考试模式</el-dropdown-item>
                </el-dropdown-menu>
              </template>
            </el-dropdown>
          </li>
          <li><router-link to="/myPaperList">我的考试/练习</router-link></li>
          <li><router-link to="/scoreTable">我的分数</router-link></li>
          <li><router-link to="/message">考试动态</router-link></li>
          <li class="right">
            <el-dropdown>
              <el-button class="el-dropdown-link" round>
                {{user.studentName}}<el-icon class="el-icon--right"><arrow-down /></el-icon>
              </el-button>
              <template #dropdown>
                <el-dropdown-menu>
                  <el-dropdown-item><router-link to="/manager">个人中心</router-link></el-dropdown-item>
                  <el-dropdown-item class="exit" @click="exit()">退出</el-dropdown-item>
                </el-dropdown-menu>
              </template>
            </el-dropdown>
          </li>
        </ul>
      </el-col>
    </el-row>
    <!--路由区域-->
    <div>
      <router-view></router-view>
    </div>
    <!--组件底部-->
    <stu-footer></stu-footer>
  </div>
</template>

<script>
import StuFooter from "@/components/student/stuFooter";
import {computed, onMounted, reactive, ref} from "vue";
import {useRouter} from "vue-router/dist/vue-router";
import {ArrowDown,Reading} from '@element-plus/icons-vue'
import {useStore} from "vuex";
import {ElMessage} from "element-plus";
export default {
  // eslint-disable-next-line vue/multi-word-component-names
  name: "index",
  components: {StuFooter,ArrowDown,Reading},

  setup(){
    const router = useRouter()
    const store = useStore()
    let flag = ref(false)
    let user = reactive({})
    onMounted(()=>{
      // eslint-disable-next-line no-undef
      let studentName = $cookies.get("name")
      // eslint-disable-next-line no-undef
      let studentId = $cookies.get("id")
      user.studentName = studentName
      user.studentId = studentId
    })
    let mode = computed(()=>{
      return store.state.PracticeOrExam === true ? "练习模式":"考试模式"
    })
    function exit(){
      router.push({path: '/'})
      ElMessage({
        type: 'info',
        message: '退出登录',
      })
      // eslint-disable-next-line no-undef
      $cookies.remove("name") //清除cookie
      // eslint-disable-next-line no-undef
      $cookies.remove("id")
      // eslint-disable-next-line no-undef
      $cookies.remove("role")

    }
    function practice(){
      store.commit('changeMode',true)
    }
    function exam(){
      store.commit('changeMode',false)
    }
    function index(){
      router.push({path: '/student'})
    }
    return{
      flag,
      user,
      mode,
      exit,
      exam,
      practice,
      index
    }
  }
}
</script>

<style scoped>
.right{
  margin-right: 6px;
}
#main .space {
  margin: 0 auto;
  box-shadow: 0 0 10px 4px rgba(1,149,255,0.1);
  background-color: #fff;
}
.icon-kaoshi{
  margin: 0 auto;
}
.list .el-dropdown-link a{
  text-decoration: none;
  color: #1BA8EAFF;
}
li{
  list-style: none;
  height: 60px;
  line-height: 60px;
}
#main .list{
  display: flex;
  flex-direction: row;
}
#main .list li {
  padding: 0 20px;
  cursor: pointer;
}
#main .list li:hover {
  background-color: #0195ff;
}
#main .list li:hover a{
  color: #fff;
}
#main .list .right{
  margin-left: auto;
  position: relative;
}
#main .list li.right :hover a{
  color: #000;
}
#main .list .logo{
  display: flex;
  font-weight: bold;
}
#main .list .logo i{
  font-size: 50px;
}
.right{
  text-align: center;
  position: absolute;
  top: 0px;
  left: 0px;
  display: flex;
  flex-direction: column;
  border-radius: 2px;
  background-color: #fff;
}
.right .msg p{
  height: 40px;
  line-height: 40px;
  width: 105px;
}
.right .msg p:hover {
  background-color: #0195ff;
}
.el-dropdown-link {
  text-align: center;
  position: relative;
  top: 15px;
  right: 0px;
  color: #409eff;
}
.icon-kaoshi{
  margin-top: -10px;
}
</style>